package com.hnevc.androidui10;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.io.InputStream;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        InputStream in = this.getResources().openRawResource(R.raw.data);
        try {
            byte[] bytes=new byte[in.available()];
            in.read(bytes);
            String temp =new String(bytes);
            Toast.makeText(this, temp, Toast.LENGTH_SHORT).show();

            JSONObject jsonObject=new JSONObject(temp);
            String authorit=jsonObject.getString("autor");
           JSONArray array=  jsonObject.getJSONArray("publisher");
            String publishers=(String) array.get(0);
            Toast.makeText(this, publishers, Toast.LENGTH_SHORT).show();

        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }
}
